Skip to content

[CSV-334] Close file writers when printer construction fails - #648

Open
hutiefang76 wants to merge 1 commit into
apache:masterfrom
hutiefang76:frank/fix-csv334-close-writer-on-creation-failure-20261205
Open

hutiefang76 wants to merge 1 commit into
apache:masterfrom
hutiefang76:frank/fix-csv334-close-writer-on-creation-failure-20261205

Conversation

@hutiefang76

Copy link
Copy Markdown

Jira: CSV-334, reported by Qiuye Wang.

CSVFormat.print(Path, Charset) opens a writer before constructing a printer. If writing a header during construction fails, the caller never receives a printer to close. Close the writer on that failure path, keep the original exception, and suppress a distinct close failure. A caller-supplied appendable remains with the caller if printer construction fails.

The close-on-failure regression failed on the original behavior for both distinct and identical exception instances. Ownership controls and both regression cases pass after the fix. A POSIX FIFO probe that closes its reader during header output still reports the same broken pipe. The Java process retains one extra file descriptor with the original code and none with the fix.

The default Maven build on Java 17 passed with 982 tests executed and 11 existing skips. The Java 8 format suite passed all 120 tests, including the four added cases.

  • Read the contribution guidelines for this project.
  • Read the ASF Generative Tooling Guidance.
  • AI assistance: DeepSeek V4 Pro drafted the regression and implementation approach and reviewed the patch. OpenAI Codex prepared the final code and pull request text and verified the tests and file descriptor behavior.
  • Run a successful build using the default Maven goal.
  • Add tests that fail without the runtime fix.
  • Describe the problem, approach, and validation.
  • Use a meaningful commit message with Assisted-By trailers.

Close the writer opened by the path overload if writing the header fails.
Keep the original construction failure and suppress a distinct close failure.

Assisted-By: DeepSeek V4 Pro
Assisted-By: OpenAI Codex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant